const ConsulConfig = require('../consul/server')
const config = require('../config/dev')
const consul = new ConsulConfig();

// 初始化consul
async function consulInit() {
    await consul.registerServer({
        name: config.application.name,
        address: config.application.host,
        port: config.application.port,
        check: {
            http: `http://${config.application.host}:${config.application.port}/health`,
            interval: '10s',
            timeout: '5s'
        }
    }, (err, res) => {
        if (err) {
            console.log(`${new Date().toISOString()}:consul register err... + ${err}`)
        } else {
            console.log(`${new Date().toISOString()}:consul register success...`)
        }
    })
}

module.exports = {
    consulInit
}
